/**
 * 
 */
package co.gov.medellin.sdep.sisdep.gestion.service;

import java.util.Date;
import java.util.List;

import co.gov.medellin.sdep.sisdep.gestion.exception.EstConceptoCaracException;
import co.gov.medellin.sdep.sisdep.gestion.exception.EstConceptoCaracRuntimeException;
import co.gov.medellin.sdep.sisdep.gestion.exception.descriptor.EstConceptoCaracMessageDescriptor;
import co.gov.medellin.sdep.sisdep.common.message.MessageDescriptorConstant;
import co.gov.medellin.sdep.sisdep.common.service.BaseService;
import co.gov.medellin.sdep.sisdep.model.EstConceptoCarac;
import co.gov.medellin.sdep.sisdep.model.dao.impl.IEstConceptoCaracDAOT;

/**
 * @author Usuario
 *
 */
public class EstConceptoCaracServiceImpl extends BaseService implements IEstConceptoCaracService {

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                 init()
	//----------------------------------------------------------------------

	/**
	 * default serial version
	 */
	private static final long serialVersionUID = 1L;
	/** */
	private IEstConceptoCaracDAOT estConceptoCaracDAO;

	/**
	 * 
	 */
	public EstConceptoCaracServiceImpl() {
	}

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                  end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                     init()
	//----------------------------------------------------------------------

	/**
	 * 
	 */
	public void insert(EstConceptoCarac estConceptoCarac) throws EstConceptoCaracException {
		try{
			estConceptoCarac.setUsuarioCrea(getPrincipalUser());
			estConceptoCarac.setFechaCrea(new Date());
			getEstConceptoCaracDAO().insert(estConceptoCarac);
		}catch (Exception e) {
			Object [] infoError = {
				estConceptoCarac.getCodigo()
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new EstConceptoCaracException(new EstConceptoCaracMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new EstConceptoCaracException(new EstConceptoCaracMessageDescriptor(MessageDescriptorConstant.SAVE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void update(EstConceptoCarac estConceptoCarac) throws EstConceptoCaracException {
		try{
			estConceptoCarac.setUsuarioModifica(getPrincipalUser());
			estConceptoCarac.setFechaModifica(new Date());
			getEstConceptoCaracDAO().update(estConceptoCarac);
		}catch (Exception e) {
			Object [] infoError = {
				estConceptoCarac.getCodigo()
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new EstConceptoCaracRuntimeException(new EstConceptoCaracMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new EstConceptoCaracRuntimeException(new EstConceptoCaracMessageDescriptor(MessageDescriptorConstant.UPDATE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void delete(EstConceptoCarac estConceptoCarac) throws EstConceptoCaracException {
		try {
			estConceptoCarac.setUsuarioModifica(getPrincipalUser());
			estConceptoCarac.setFechaModifica(new Date());
			getEstConceptoCaracDAO().delete(estConceptoCarac);
		}catch (Exception e) {
			Object [] infoError = {
				estConceptoCarac.getCodigo()
			};
			throw new EstConceptoCaracRuntimeException(new EstConceptoCaracMessageDescriptor(MessageDescriptorConstant.DELETE), infoError, e);
		}
	}

	/**
	 * @return 
	 * 
	 */
	public final List load(int start,int max, EstConceptoCarac estConceptoCarac) throws EstConceptoCaracException {
		try{
			//return getEstConceptoCaracDAO().getAllEstConceptoCaracPaginated(start, max, criteria);
			return getEstConceptoCaracDAO().load();
		}catch (Exception e) {
			Object [] infoError = null;
			throw new EstConceptoCaracRuntimeException(new EstConceptoCaracMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}
	

	/**
	 * @return 
	 * 
	 */
	public final List loadByNombre(int start,int max, EstConceptoCarac estConceptoCarac) throws EstConceptoCaracException {
		try{
			//return getEstConceptoCaracDAO().getAllEstConceptoCaracPaginated(start, max, criteria);
			return getEstConceptoCaracDAO().loadByNombre(estConceptoCarac);
		}catch (Exception e) {
			Object [] infoError = null;
			throw new EstConceptoCaracRuntimeException(new EstConceptoCaracMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}

	/**
	 * 
	 */
	public final EstConceptoCarac get(long id) throws EstConceptoCaracException {
		try{
			return getEstConceptoCaracDAO().findByPrimaryKey(id);
		}catch (Exception e) {
			Object [] infoError = {new Long(id)};
			throw new EstConceptoCaracRuntimeException(new EstConceptoCaracMessageDescriptor(MessageDescriptorConstant.GET), infoError, e);
		}
	}

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                      end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- getters and setters                                         init()
	//----------------------------------------------------------------------

	/**
	 * @author Usuario
	 *
	 */
	public IEstConceptoCaracDAOT getEstConceptoCaracDAO() {
		return estConceptoCaracDAO;
	}

	/**
	 * @author Usuario
	 *
	 */
	public void setEstConceptoCaracDAO(IEstConceptoCaracDAOT estConceptoCaracDAO) {
		this.estConceptoCaracDAO = estConceptoCaracDAO;
	}

	//----------------------------------------------------------------------
	//--- getters and setters                                          end()
	//----------------------------------------------------------------------

}
